package h.ku.lang.modules
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import h.ku.eval.Args;
	import h.ku.lang.hkuBlock;
	import h.ku.lang.hkuObject;

	public class hkuTimer extends hkuObject
	{
		public function hkuTimer()
		{
			this.addAS3Function("in",function(a:Args):void
			{
				var block:hkuBlock = a.arguments[1] as hkuBlock;
				var t:Timer = new Timer(a.arguments[0],1)
				t.addEventListener(TimerEvent.TIMER,
					function(e:TimerEvent):void
					{
						t.stop()
						block.call(new Args(a.caller,[],null),null,true)
					})
				t.start()
				a.caller.finishFunctionEval(null)
			})
				
			this.addAS3Function("every",function(a:Args):void
			{
				var block:hkuBlock = a.arguments[1] as hkuBlock;
				var t:Timer = new Timer(a.arguments[0])
				t.addEventListener(TimerEvent.TIMER,
					function(e:TimerEvent):void
					{
						block.call(new Args(a.caller,[],null),function(v:*):void
						{
							if(v === false) t.stop()
						},true)
					})
				t.start()
				a.caller.finishFunctionEval(null)
			})
		
		}
	}
}